package com.lanyan.system.service.impl;

import java.util.List;
import java.util.stream.Collectors;
        import com.lanyan.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.lanyan.common.utils.StringUtils;
import com.lanyan.system.mapper.HotSearchMapper;
import com.lanyan.system.domain.HotSearch;
import com.lanyan.system.domain.vo.HotSearchVo;
import com.lanyan.system.service.IHotSearchService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 热搜Service业务层处理
 *
 * @author lanyan
 * @date 2024-11-26
 */
@Service
public class HotSearchServiceImpl  extends ServiceImpl<HotSearchMapper,HotSearch> implements IHotSearchService

{
    @Autowired
    private HotSearchMapper hotSearchMapper;

    /**
     * 查询热搜
     *
     * @param hotSearchId 热搜主键
     * @return 热搜
     */
    @Override
    public HotSearch selectHotSearchByHotSearchId(Long hotSearchId)
    {
        return this.getById(hotSearchId);
    }

    /**
     * 查询热搜Vo列表
     *
     * @param hotSearch 热搜
     * @return 热搜
     */
    @Override
    public List<HotSearchVo> selectHotSearchVoList(HotSearch hotSearch)
    {
        return selectHotSearchList(hotSearch)
                .stream()
                .map(x -> (HotSearchVo)x)
                .collect(Collectors.toList());
    }
    /**
     * 查询热搜列表
     *
     * @param hotSearch 热搜
     * @return 热搜
     */
    @Override
    public List<HotSearch> selectHotSearchList(HotSearch hotSearch)
    {
        LambdaQueryChainWrapper<HotSearch> wrapper = this.lambdaQuery().eq(HotSearch::getDelFlag,"0");
        if (StringUtils.isNotEmpty(hotSearch.getName())) {
            wrapper.like(HotSearch::getName, hotSearch.getName());
        }
        if (hotSearch.getNum() != null) {
            wrapper.eq(HotSearch::getNum, hotSearch.getNum());
        }
        return wrapper.list();
    }

        /**
         * 新增热搜
         *
         * @param hotSearch 热搜
         * @return 结果
         */
    @Override
        public boolean insertHotSearch(HotSearch hotSearch)
        {
                    hotSearch.setCreateTime(DateUtils.getNowDate());
                return this.save(hotSearch);
        }

        /**
         * 修改热搜
         *
         * @param hotSearch 热搜
         * @return 结果
         */
    @Override
        public boolean updateHotSearch(HotSearch hotSearch)
        {
                    hotSearch.setUpdateTime(DateUtils.getNowDate());
            return this.updateById(hotSearch);
        }

        /**
         * 批量删除热搜
         *
         * @param hotSearchIds 需要删除的热搜主键
         * @return 结果
         */
    @Override
        public boolean deleteHotSearchByHotSearchIds(Long[] hotSearchIds)
        {
            return this.lambdaUpdate().set(HotSearch::getDelFlag,"1").in(HotSearch::getHotSearchId,hotSearchIds).update();
        }

        /**
         * 删除热搜信息
         *
         * @param hotSearchId 热搜主键
         * @return 结果
         */
    @Override
        public boolean deleteHotSearchByHotSearchId(Long hotSearchId)
        {
            return this.lambdaUpdate().set(HotSearch::getDelFlag,"1").eq(HotSearch::getHotSearchId,hotSearchId).update();
        }
    }
